<?php
    /**
    * Product Categories get list
    * return in Json format
    * @author trungdt
    * @since Sep 27, 2011
    * 
    * Change logs
    * Oct 2, 2011 - trungdt - Make this action compatible with product edit page
    */
    if (!defined('EXPONENT')) exit('');
    if (exponent_permissions_check(array('administrate','configure'),$loc)){
        //// pagination
        $id = 0;
        $sql_where = null;
        if(isset($_REQUEST['id_question']))
        {
            $id = intval($_REQUEST['id_question']);
            $sql_where .= "id_question='".$id."'";
            
        }
        $page=1;
        if (isset($_REQUEST['page']))
            $page=intval($_REQUEST['page']);
        $pageSize=10;
        if (isset($_REQUEST['pageSize']))
            $pageSize=intval($_REQUEST['pageSize']);
        $start=($page-1)*$pageSize;
        $sql = "
        SELECT {$db->prefix}surveymodule_question.*,{$db->prefix}surveymodule_answer.*
from {$db->prefix}surveymodule_question,{$db->prefix}surveymodule_answer
WHERE {$db->prefix}surveymodule_question.id = {$db->prefix}surveymodule_answer.id_question and {$sql_where} LIMIT {$start},{$pageSize}
        ";
       $data=$db->selectObjectsBySql($sql);
        //$data=$db->selectObjects('maillinglist');
        $ret_object = null;
        // đưa ra t^ổng s^ố record sẽ trả v^ề
        $ret_object->total = $db->countObjects('surveymodule_answer');
        $ret_object->rows = $data;
        
        echo json_encode($ret_object);
    }
    die();
?>